#include <iostream>
#include <string>
#include <queue>

using namespace std;
// 这是一个bfs的写法 未完成

string split_token = ",";
string null_token = "null";

typedef struct Node {
    int val;
    Node *left;
    Node *right;
    Node(int x) : val(x), left(nullptr), right(nullptr) {}
}*PNode;

Node *Deserialize(string seqs) {
    //write ur code here.
    PNode root;
    PNode *proot = &root;
    queue<PNode> treeque;
    treeque.push(*proot);
    for (auto &c : seqs) {

    }
}

string Serialize(Node *root) {
    //write ur code here.
    queue<PNode> treeque;
    string code;
    treeque.push(root);
    while (!treeque.empty()) {
        PNode root = treeque.front();treeque.pop();
        if (root == nullptr) {
            code += null_token;
            treeque.push(nullptr);
            treeque.push(nullptr);
            continue;
        }
        code += to_string(root->val);
        treeque.push(root->left);
        treeque.push(root->right);
    }
    return code;
}

// #include "tools.h"

void PreOrderprintTree(Node *root) {
    if (root == nullptr) { cout << "#";return; }
    cout << root->val;
    PreOrderprintTree(root->left);
    PreOrderprintTree(root->right);
}
void BFSprintTree(Node *root) {
    if (root == nullptr) { cout << null_token;return; }
    cout << root->val << split_token;
    PreOrderprintTree(root->left);
    PreOrderprintTree(root->right);
}

int main(int argc, char const *argv[]) {
    /* code */
    Node *root = new Node(1);
    root->left = new Node(2);
    root->left->left = new Node(3);
    root->left->left->left = new Node(4);
    cout << "加密前为: ";
    PreOrderprintTree(root); cout << endl;
    string se = Serialize(root);
    cout << "加密后为: " << se << endl;
    // Node *deroot = Deserialize(se);
    // cout << "解密后为: ";
    // PreOrderprintTree(deroot); cout << endl;
    return 0;
}


